//初始化流程信息
$(function(){
	//使用ajax获取流程信息
	//获取表单KEY
	var formName = $("#form_identity_").val();
	//获取流程定义
	var flowKey = $("#flowKey_").val();
	//业务主键
	var businessId = $("#businessId").val();
	$.ajax({
	    type: 'POST',
	    async:false,
	    url:PATH+"/bpm/workflow/getWorkFlowInfoByView",
	    data: {formName:formName,flowKey:flowKey,businessId:businessId},
	    dataType: "json",
	    success: initWorkFlow,
	    error:error,
	});
});

//初始化流程
function initWorkFlow(data){
	//是否启动流程
	initApproveInfo(data);
}

function ShowDIV() {
    $("#BgDiv").css({ display: "block", height: $(document).height() });
    $("#DialogDiv").css("top", "100px");
    $("#DialogDiv").css("display", "block");
}

function closeDiv() {
    $("#BgDiv").css("display", "none");
    $("#DialogDiv").css("display", "none");
}

function btn_click_flow(){
	if(validateForm()) {
		ShowDIV();
		var actionName = $("input[name='actionName']:checked").val();
		var taskId = $("#taskId").val();
		var bpm_flow_excute_type = $("#bpm_flow_excute_type").val();
		var opinion = $("#opinionIdea").val();	
		var nodeId = $("input[name='nodeId']:checked").val();
		var editNodeIds = $("#editNodeIds").val();
		var userIds = $("#userIds").val();
		$.ajax({
		    type: 'POST',
		    async:true,
		    url:PATH+"/bpm/workflow/executeTask",
		    data: {is_work_flow_:true,taskId:taskId,bpm_flow_excute_type:bpm_flow_excute_type,actionName:actionName,opinion:opinion,nodeId:nodeId,editNodeIds:editNodeIds,userIds:userIds},
		    dataType: "json",
		    success: function(data){
		    	if(data){
		    		closeDiv();
		    		alert("流程提交成功!");
		    		window.location.reload();
		    	}else{
		    		alert("流程提交失败,请重新提交或联系管理员!");
		    	}
		    },
		    error:error,
		});
	} else {
		return false;
	}
	
}
//执行任务是否成功
function extSuccess(data){
	alert("流程提交成功！");
	window.close();
}

function error(){
	alert("流程提交失败");
}